﻿using AutoMapper;
using AutoMapperTest.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AutoMapperTest.DTO
{
    public static class MappingConfiguration
    {
        public static void Configure(IMapperConfigurationExpression cfg)
        {
            cfg.CreateMap<InspRecordDTO, InspRecord>()
                .ForMember(c => c.ID, opt => opt.Ignore());
            cfg.CreateMap<InspRecord, InspRecordDTO>();

            cfg.CreateMap<InspGroupRecordDTO, InspGroupRecord>()
                .ForMember(c => c.GID, opt => opt.Ignore())
                 .ForMember(c => c.ID, opt => opt.Ignore())
                  .ForMember(c => c.IR, opt => opt.Ignore());
            cfg.CreateMap<InspGroupRecord, InspGroupRecordDTO>();

            //cfg.CreateMap<ICollection<InspItemRecord>, List<InspItemRecordDTO>>();
            //cfg.CreateMap<List<InspItemRecordDTO>, ICollection<InspItemRecord>>();

            cfg.CreateMap<InspItemRecordDTO, InspItemRecord>()
                .ForMember(d => d.CoordinateDetails, opt => opt.MapFrom(y => (new CustomerTypeConverter()).CustomerConvert(y)))
                .ForMember(d => d.ID, opt => opt.Ignore())
                .ForMember(d => d.IG, opt => opt.Ignore())
                .ForMember(d => d.IID, opt => opt.Ignore());

            cfg.CreateMap<InspItemRecord, InspItemRecordDTO>()
                .ForMember(c => c.ErrRow, opt => opt.MapFrom(x => x.CoordinateDetails.Select(y => y.Y)))
                .ForMember(c => c.ErrCol, opt => opt.MapFrom(x => x.CoordinateDetails.Select(y => y.X)))
                .ForMember(c => c.ErrDiff, opt => opt.MapFrom(x => x.CoordinateDetails.Select(y => y.Diff)))
                .ForMember(c => c.ErrType, opt => opt.MapFrom(x => x.CoordinateDetails.Select(y => y.Type)))
                .ForMember(c => c.ErrValue, opt => opt.MapFrom(x => x.CoordinateDetails.Select(y => y.Value)))
                .ForMember(c => c.InspedImg, opt => opt.Ignore());

        }
    }
}
